|
|
@@ -90,18 +90,8 @@ namespace :sync do
|
90
|
90
|
end
|
91
|
91
|
end
|
92
|
92
|
|
93
|
|
- #
|
94
|
|
- # Reads the database credentials from the local config/database.yml file
|
95
|
|
- # +db+ the name of the environment to get the credentials for
|
96
|
|
- # Returns username, password, database
|
97
|
|
- #
|
98
|
|
- def database_config(db)
|
99
|
|
- database = YAML::load_file('config/database.yml')
|
100
|
|
- return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'], database["#{db}"]['host']
|
101
|
|
- end
|
102
|
|
-
|
103
|
|
- # Used by remote_database_config to parse the remote .env file. Depends on the dotenv-rails gem.
|
104
|
|
- class RemoteEnvLoader < Dotenv::Environment
|
|
93
|
+ # Used by database_config and remote_database_config to parse database configs that depend on .env files. Depends on the dotenv-rails gem.
|
|
94
|
+ class EnvLoader < Dotenv::Environment
|
105
|
95
|
def initialize(data)
|
106
|
96
|
@data = data
|
107
|
97
|
load
|
|
|
@@ -123,6 +113,23 @@ namespace :sync do
|
123
|
113
|
end
|
124
|
114
|
|
125
|
115
|
#
|
|
116
|
+ # Reads the database credentials from the local config/database.yml file
|
|
117
|
+ # +db+ the name of the environment to get the credentials for
|
|
118
|
+ # Returns username, password, database
|
|
119
|
+ #
|
|
120
|
+ def database_config(db)
|
|
121
|
+ local_config = File.read('config/database.yml')
|
|
122
|
+ local_env = File.read('.env')
|
|
123
|
+
|
|
124
|
+ database = nil
|
|
125
|
+ EnvLoader.new(local_env).with_loaded_env do
|
|
126
|
+ database = YAML::load(ERB.new(local_config).result)
|
|
127
|
+ end
|
|
128
|
+
|
|
129
|
+ return database["#{db}"]['username'], database["#{db}"]['password'], database["#{db}"]['database'], database["#{db}"]['host']
|
|
130
|
+ end
|
|
131
|
+
|
|
132
|
+ #
|
126
|
133
|
# Reads the database credentials from the remote config/database.yml file
|
127
|
134
|
# +db+ the name of the environment to get the credentials for
|
128
|
135
|
# Returns username, password, database
|
|
|
@@ -132,7 +139,7 @@ namespace :sync do
|
132
|
139
|
remote_env = capture("cat #{current_path}/.env")
|
133
|
140
|
|
134
|
141
|
database = nil
|
135
|
|
- RemoteEnvLoader.new(remote_env).with_loaded_env do
|
|
142
|
+ EnvLoader.new(remote_env).with_loaded_env do
|
136
|
143
|
database = YAML::load(ERB.new(remote_config).result)
|
137
|
144
|
end
|
138
|
145
|
|